package com.ruoyi.peach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peach.domain.CollectTask;
import com.ruoyi.peach.service.ICollectTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集任务Controller
 * 
 * @author ruoyi
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/peach/collectTask")
public class CollectTaskController extends BaseController
{
    @Autowired
    private ICollectTaskService collectTaskService;

    /**
     * 查询数据采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('peach:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(CollectTask collectTask)
    {
        startPage();
        System.out.println(collectTask);
        List<CollectTask> list = collectTaskService.selectCollectTaskListWeb(collectTask);
        return getDataTable(list);
    }
    /**
     * 查询数据采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('peach:task:list')")
    @GetMapping("/list/app")
    public R listApp(CollectTask collectTask)
    {
        List<CollectTask> list = collectTaskService.selectCollectTaskList(collectTask);
        return R.ok(list);
    }


    /**
     * 导出数据采集任务列表
     */
    @PreAuthorize("@ss.hasPermi('peach:task:export')")
    @Log(title = "数据采集任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CollectTask collectTask)
    {
        List<CollectTask> list = collectTaskService.selectCollectTaskList(collectTask);
        ExcelUtil<CollectTask> util = new ExcelUtil<CollectTask>(CollectTask.class);
        util.exportExcel(response, list, "数据采集任务数据");
    }

    /**
     * 获取数据采集任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('peach:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(collectTaskService.selectCollectTaskByTaskId(taskId));
    }

    /**
     * 新增数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('peach:task:add')")
    @Log(title = "数据采集任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectTask collectTask)
    {
        return toAjax(collectTaskService.insertCollectTask(collectTask));
    }

    /**
     * 修改数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('peach:task:edit')")
    @Log(title = "数据采集任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectTask collectTask)
    {
        return toAjax(collectTaskService.updateCollectTask(collectTask));
    }

    /**
     * 删除数据采集任务
     */
    @PreAuthorize("@ss.hasPermi('peach:task:remove')")
    @Log(title = "数据采集任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(collectTaskService.deleteCollectTaskByTaskIds(taskIds));
    }
}
